home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)popup.c V1.18 3/13/95";
- #endif
- /*
- | file name - popup.c
- |===================================================================
- |
- | Example program that shows one method of doing "pop-up" inputs.
- |
- | This method uses two views created using DV-Draw. One view
- | was initially created with inputs and outputs together.
- | "Save Sub View" was used to create separate input and
- | output views.
- |
- | The output view (editatts.v) contains named "poke" objects.
- | When these objects ("LineMenu" & "ColorPalette") are selected
- | the appropriate pop-up input is drawn. The menu and palette
- | control the line and color attributes of "rect.obj".
- |
- | The input view (attsinputs.v) contains the menu and palette
- | input object. The application posts a ServiceResult function
- | which changes rect.obj's attributes and erases the pop-up input.
- | The input objects both have key bindings as follows...
- |
- | DONE_KEYS < LEFT_MOUSE, s>
- | CANCEL_KEYS < MIDDLE_MOUSE, RIGHT_MOUSE, c>
- |
- | Selecting the RIGHT_MOUSE button outside of a pop-up menu
- | causes both input objects to be erased.
- |
- | Typing a <q|Q> will exit the program.
- |
- |===================================================================
- */
- #include <windows.h>
-
-
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "editatts.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define CLIENT_LINE_MENU (OBJECT)1
- #define CLIENT_COLOR_PALETTE (OBJECT)2
-
- /* Buffer addresses of data source variables used by popups. */
- float *LineData;
- float *ColorData;
-
- /* information passed to the service routine HandleInput() */
- typedef struct
- {
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- OBJECT rect_obj; /* rectangle object to affect attributes */
- OBJECT input[2]; /* popup input objects */
- } INFO;
-
- /* Functions defined in popup.c */
- int HandleInput V_P_((OBJECT client, EVENT_REQUEST er, int label,
- OBJECT loc, ADDRESS info)); /* service result routine */
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Input object related variables */
- VIEW input_view; /* picture representation of popups */
- OBJECT input_drawing; /* graphical representation of popups */
- ADDRESS *vdplist; /* variable descriptor list for menu */
- int numvars; /* number of vdps in list */
- DSVAR dsvar; /* data source variable bound to vdp */
- INFO info; /* struct passed to service result routine */
- char *popup_name; /* name of popup input object */
-
- /* Other variables */
- OBJECT main_drawing; /* graphical representation of main view */
- int Quit = NO; /* flag to exit the program */
-
- /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
- LOCAL RECTANGLE whole_world = { XMIN, YMIN, XMAX, YMAX };
- int argc;
- char **argv;
-
-
- make_argv(&argc,&argv,GetCommandLine());
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_WINDOW_NAME, "popup",
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file,
- * TdpCreateStretch: Create a drawport with stretched coordinates
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- * Objects of the view are stretched to make the
- * the portion of the view specified as whole_world
- * fit in the specified viewport, SCREEN_VIEWPORT.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
- info.drawport = TdpCreateStretch (screen, view,
- SCREEN_VIEWPORT, &whole_world);
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TdrGetNamedObject: Gets the name of an object from
- * a drawing.
- *
- * Get the object named "rect.obj" from the view's drawing.
- */
- main_drawing = TviGetDrawing (view);
- info.rect_obj = TdrGetNamedObject (main_drawing, "rect.obj");
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen);
- TdpDraw (info.drawport);
-
- /*
- * TviLoad: Load a view in from a file,
- * TviGetDrawing: Gets a view's drawing object
- * TdrGetNamedObject: Gets the name of an object from
- * a drawing.
- *
- * Get the popup input objects from the view's drawing.
- * One input object is a menu of line types and the other
- * is a color palette.
- */
- input_view = TviLoad ("attsinputs.v");
- input_drawing = TviGetDrawing (input_view);
- info.input[0] = TdrGetNamedObject (input_drawing, "LineMenu.input");
- info.input[1] = TdrGetNamedObject (input_drawing, "ColorPalette.input");
-
- /*
- * VOinGetVarList: Gets a variable descriptor list of
- * the input object.
- * TvdGetDataSourceVariable: Gets the data source variable
- * which the variable descriptor
- * (vdp) is linked to.
- * TdsvGetBuffer: Gets data source variable (dsv)
- * buffer address.
- *
- * Obtain the vdp list for the each input object.
- * Find the data source variable which the vdp is linked
- * to. Then obtain the buffer address which the data
- * source variable is pointing to.
- */
- VOinGetVarList (info.input[0], &vdplist, &numvars);
- dsvar = TvdGetDataSourceVariable (vdplist[0]);
- LineData = (float *) TdsvGetBuffer (dsvar);
-
- VOinGetVarList (info.input[1], &vdplist, &numvars);
- dsvar = TvdGetDataSourceVariable (vdplist[0]);
- ColorData = (float *) TdsvGetBuffer (dsvar);
-
- /*
- * VUerServiceResultPost: Post a service result request
- * with the event handler.
- *
- * Post a service result request which monitors the
- * line menu and color palette input objects. Two
- * requests are posted for each input object. One specifies
- * the type of the service result flag to be generated as
- * an INPUT_DONE. INPUT_DONE indicates an input sequence
- * sequence has been completed (a menu selection was made).
- * The other request specifies INPUT_CANCEL as the service
- * result flag to be serviced. INPUT_CANCEL indicates the
- * the user cancel the input.
- */
- VUerServiceResultPost ((OBJECT) CLIENT_LINE_MENU,
- (VUERFCNFUNPTR)HandleInput, (ADDRESS) & info, (int)sizeof (info),
- info.input[0], (int) INPUT_DONE, (int) INPUT_DONE);
-
- VUerServiceResultPost ((OBJECT) CLIENT_LINE_MENU,
- (VUERFCNFUNPTR)HandleInput, (ADDRESS) & info, (int)sizeof (info),
- info.input[0], (int) INPUT_CANCEL, (int) INPUT_CANCEL);
-
- VUerServiceResultPost ((OBJECT) CLIENT_COLOR_PALETTE,
- (VUERFCNFUNPTR)HandleInput, (ADDRESS) & info, (int)sizeof (info),
- info.input[1], (int) INPUT_DONE, (int) INPUT_DONE);
-
- VUerServiceResultPost ((OBJECT) CLIENT_COLOR_PALETTE,
- (VUERFCNFUNPTR)HandleInput, (ADDRESS) & info, (int)sizeof (info),
- info.input[1], (int) INPUT_CANCEL, (int) INPUT_CANCEL);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for locator events. If the key
- * represents the character 'q' or 'Q' then quit the program.
- * Check for a selection of a popup menu.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- * VUerHandleLocEvent: Service the event.
- * This routine will check if the
- * event is used by any input objects
- * that are in the view.
- */
- location = VOloWinEventPoll (V_WAIT);
- VUerHandleLocEvent (location);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
-
- case V_BUTTONPRESS:
- /*
- * VOloButton: Returns the button that was pressed
- */
- if (VOloButton (location) == 3)
- {
- TdpEraseObject (info.drawport, info.input[0]);
- TdpEraseObject (info.drawport, info.input[1]);
- }
- else
- /*
- * TloGetSelectedObjectName: Get the name of the
- * selected object.
- * TdpDrawObject: Draw a specific object within a drawport.
- *
- * Draw the popup input object when selected. The object
- * name is used to identify the object.
- */
- popup_name = TloGetSelectedObjectName (location);
- if (popup_name)
- {
- if (strcmp ("LineMenu", popup_name) == 0)
- TdpDrawObject (info.drawport, info.input[0]);
- else if (strcmp ("ColorPalette", popup_name) == 0)
- TdpDrawObject (info.drawport, info.input[1]);
- }
- break;
-
- default:
- break;
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * VUerClearAll: Clears a client's event requests
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- VUerClearAll ((OBJECT) CLIENT_LINE_MENU);
- VUerClearAll ((OBJECT) CLIENT_COLOR_PALETTE);
- TdpDestroy (info.drawport);
- TviDestroy (view);
- TviDestroy (input_view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
-
- /*--------------
- * HandleInput -- Perform the appropriate action based
- * on the user's selection from the popup input object.
- * Change the attributes of the object based on the
- * selection from the popup.
- */
- /*ARGSUSED*/
- int
- HandleInput (client, er, label, loc, args)
- OBJECT client;
- EVENT_REQUEST er;
- int label;
- OBJECT loc;
- ADDRESS args;
- {
- ATTRIBUTES atts; /* Attribute structure for objects */
- INFO *info = (INFO *)args;
-
- /*
- * TdpEraseObject: Erase an object within a drawport
- * erase popup input object which is
- * being serviced.
- */
- TdpEraseObject (info->drawport, info->input[client - 1]);
-
- /*
- * VOobAtGet: Get the current attributes of an object
- * VOobAtSet: Set new attributes in an object
- * TdpDrawObject: Draw a specific object within a drawport
- *
- * Erase the rectangle object from the main drawport.
- * Then obtain the current attributes of the rectangle
- * object. If the user selected from the line menu
- * check the value of the data buffer. A value
- * greater than four will affect the line width used
- * whereas a value of 1 - 4 will modify the pattern
- * used for the line. If the user selected from the
- * color palette then the foreground color of the
- * rectangle object will be modified. Set the
- * attributes and draw the object with the new
- * attributes.
- */
- if (label == INPUT_DONE)
- {
- TdpEraseObject (info->drawport, info->rect_obj);
- VOobAtGet (info->rect_obj, &atts);
- switch (client)
- {
- case CLIENT_LINE_MENU:
- if (*LineData > 4)
- atts.line_width = (char) (*LineData - 4);
- else
- atts.line_type = (char) (*LineData);
- break;
-
- case CLIENT_COLOR_PALETTE:
- atts.foreground_color = VOcoCreate (COLOR_INDEX,
- (LONG) * ColorData, (LONG) 0, (LONG) 0);
- break;
- }
- VOobAtSet (info->rect_obj, &atts);
- TdpDrawObject (info->drawport, info->rect_obj);
- }
-
- return (int) INPUT_USED;
- }
-